package com.gxa.saas.portal.service.impl;

import com.gxa.saas.core.entity.domain.luoj.PictureDo;
import com.gxa.saas.core.entity.dto.luoj.CollectionDTO;
import com.gxa.saas.portal.mapper.CollectionMapper;
import com.gxa.saas.portal.service.CollectionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Throwable.class)
@Validated
public class CollectionServiceImpl implements CollectionService {

    @Resource
    private CollectionMapper collectionMapper;

    @Override
    public Integer addCollection(@Validated CollectionDTO collection) {
        int insert = collectionMapper.insert(collection);
        return insert;
    }

    @Override
    public Integer cancelCollection(@Validated CollectionDTO collection) {
        Map map = new HashMap<>();
        map.put("user_id",collection.getUserId());
        map.put("commodity_id",collection.getCommodityId());
        int i = collectionMapper.deleteByMap(map);
        return i;
    }

    @Override
    public List<PictureDo> queryAllCollection(@Validated @NotNull(message = "用户id不能为空") Integer userId) {
        List<PictureDo> pictureDTOS = collectionMapper.queryAllCollection(userId);
        return pictureDTOS;
    }
}
